package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.ui.view.MdStyleProgress

/**
 * @author:hxw
 * @date  :2022/12/8
 * @desc  :
 */
class RxPayDialog(context: Context?) : RxDialog(context!!) {

    lateinit var cancelView: AppCompatTextView
    lateinit var sureView: AppCompatTextView
    lateinit var tvPayLine: TextView
    lateinit var tvDialogPayClose: AppCompatTextView
    lateinit var clPayBottom: ConstraintLayout
    private lateinit var mdStyleProgress: MdStyleProgress
    private lateinit var tvPayDialogContent: AppCompatTextView

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_pay, null)
        cancelView = dialogView.findViewById(R.id.tv_pay_dialog_cancel)
        sureView = dialogView.findViewById(R.id.tv_pay_dialog_sure)
        mdStyleProgress = dialogView.findViewById(R.id.mdStyleProgress_pay_dialog)
        tvPayDialogContent = dialogView.findViewById(R.id.tv_pay_dialog_content)
        tvPayLine = dialogView.findViewById(R.id.tv_dialog_pay_line)
        tvDialogPayClose = dialogView.findViewById(R.id.tvDialogPayClose)
        clPayBottom = dialogView.findViewById(R.id.cl_dialog_pay_bottom)
        setContentView(dialogView)
    }

    fun showBottomView() {
        tvPayLine.visibility = View.VISIBLE
        clPayBottom.visibility = View.VISIBLE
    }

    fun showBottomBtnSingle(){
        tvPayLine.visibility = View.VISIBLE
        tvDialogPayClose.visibility = View.VISIBLE
    }

    fun setSureListener(listener: View.OnClickListener?) {
        sureView.setOnClickListener(listener)
    }

    fun setCancelListener(listener: View.OnClickListener?) {
        cancelView.setOnClickListener(listener)
        tvDialogPayClose.setOnClickListener(listener)
    }

    fun setCancelBtnContent(textLeft: String) {
        if (textLeft.isEmpty()) {
            return
        }
        cancelView.text = textLeft
    }

    fun setSureBtnContent(textRight: String) {
        if (textRight.isEmpty()) {
            return
        }
        sureView.text = textRight
    }

    fun loadingDialog() {
        if (mdStyleProgress.status != MdStyleProgress.Status.Loading) {
            mdStyleProgress.status = MdStyleProgress.Status.Loading
        }
    }

    fun successAnimDialog() {
        if (mdStyleProgress.status != MdStyleProgress.Status.LoadSuccess) {
            mdStyleProgress.status = MdStyleProgress.Status.LoadSuccess
            mdStyleProgress.startAnima()
        }
    }

    fun failAnimDialog() {
        if (mdStyleProgress.status != MdStyleProgress.Status.LoadFail) {
            mdStyleProgress.status = MdStyleProgress.Status.LoadFail
            mdStyleProgress.setProColor(Color.parseColor("#e91e63"))
            mdStyleProgress.failAnima()
        }
    }

    fun setDialogContent(content: String) {
        tvPayDialogContent.text = content
    }

}